
# 24 RGB values, one for each 15-degree hue incr around the HSV color wheel
wheel = [
    (255,0,0),
    (255,51,0),
    (255,102,0),
    (255,128,0),
    (255,153,0),
    (255,178,0),
    (255,204,0),
    (255,229,0),
    (255,255,0),
    (204,255,0),
    (153,255,0),
    (51,255,0),
    (0,204,0),
    (0,178,102),
    (0,153,153),
    (0,102,178),
    (0,51,204),
    (25,25,178),
    (51,0,153),
    (64,0,153),
    (102,0,153),
    (153,0,153),
    (204,0,153),
    (229,0,102),
]

# Offsets used to yield different color cycling methods
analogicOffsets = [ 0, 12, 18, 6, 1, 13, 19, 7 ]
tetradOffsets = [ 0, 22, 2, 1, 23, 3 ]
triadOffsets = [ 0, 4, 6, 2, 5, 3, 7, 1 ]

# Generate index values (into 'wheel') for each cycling method

analogicSteps = []
for offset in analogicOffsets:
    analogicSteps.append(offset)
    analogicSteps.append((offset + 2) % 24)
    analogicSteps.append((offset + 4) % 24)

tetradSteps = []
for offset in tetradOffsets:
    tetradSteps.append(offset)
    tetradSteps.append((offset + 4) % 24)
    tetradSteps.append((offset + 12) % 24)
    tetradSteps.append((offset + 16) % 24)

triadSteps = []
for offset in triadOffsets:
    triadSteps.append(offset)
    triadSteps.append((offset + 8) % 24)
    triadSteps.append((offset + 16) % 24)

# Generate color cycle values from a given stepping pattern
def cycle(steps):
    for n in xrange(len(wheel)):
        yield wheel[steps[n]]
    
# Bake color cycles into lists for random access
analogicColors = list(rgb for rgb in cycle(analogicSteps))
tetradColors = list(rgb for rgb in cycle(tetradSteps))
triadColors = list(rgb for rgb in cycle(triadSteps))

def get_color(colors, index):
    return colors[index % len(colors)]
    
